package com.link.base.base.project.controller;

import com.link.base.base.project.model.Project;
import com.link.base.base.project.service.ProjectService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 项目
 *
 * @author 阳晓琳
 * @date 2020-09-21 16:36:57
 */
@Controller
@RequestMapping("/link/project")
public class ProjectController extends BasicController<Project> {

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private ProjectService projectService;

    @Override
    public BasicService<Project> getBasicService() throws Exception {
        return projectService;
    }

    /**
     *项目报价审批
     *
     * @author 王昊
     * @date 2020/11/4
     */
    @RequestMapping(value = "/projectQuoteSubmit", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> projectQuoteSubmit(@JsonParam Project entity, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            Project newProject = projectService.queryById(entity);
            if (!"QuoteStage".equals(newProject.getProjectStage())) {
                throw new RuntimeException("非报价阶段不可提交!");
            }
            projectService.projectQuoteSubmit(entity);
            result.put("newRow",entity);
            result.put("success", true);
        } catch (Exception e) {
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     *项目报价提交
     *
     * @author 王昊
     * @date 2020/11/4
     */
    @RequestMapping(value = "/submitInfo", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> submitInfo(@JsonParam Project entity, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            projectService.submitInfo(entity);
            result.put("newRow",entity);
            result.put("success", true);
        } catch (Exception e) {
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     *项目报价审批
     *
     * @author 王昊
     * @date 2020/11/4
     */
    @RequestMapping(value = "/projectYearTotalReportPage", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> projectYearTotalReportPage(@JsonParam Project entity, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            List<Project> list = projectService.projectYearTotalReportPage(entity);
            result.put("rows",list);
            result.put("success", true);
        } catch (Exception e) {
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     * 项目客户层级关系报表
     * @param entity
     * @param session
     * @param request
     * @return
     */
    @RequestMapping(value = "/projectAccountReport", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> projectAccountReport(@JsonParam Project entity, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            List<Project> list = projectService.projectAccountReport(entity);
            result.put("result",list);
            result.put("success", true);
        } catch (Exception e) {
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
